package org.techism.client;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;

public class TagPanelHelper {

    public static void fillTagPanel(final Map<String, Integer> result, final ClickHandler handler,
            final HorizontalPanel tagPanel) {
        final List<String> keys =  new ArrayList<String>(result.keySet());
        final FlowPanel panel = new FlowPanel();
        tagPanel.add(panel);

        if (keys.size() == 0) {
            panel.add(new Label("<Keine Einträge vorhanden>"));
        } else {
            panel.add(new Label("Tags:"));
        }

        for (final String tag : keys) {
            final Anchor anchor = new Anchor(tag);
            anchor.addClickHandler(handler);
            anchor.setStyleName("taglink");
            panel.add(anchor);
            final HTML html = new HTML(",&nbsp;");
            html.setStyleName("taglink");
            panel.add(html);
        }
        final HTML html = new HTML("<br/>");
        panel.add(html); panel.add(html); panel.add(html);
        final Anchor anchor = new Anchor("Alles anzeigen");
        anchor.addClickHandler(handler);
        anchor.setStyleName("taglink");
        panel.add(anchor);
    }
}
